layui.define(['form', 'laydate', 'table'], function (exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var highlevelTalentsTable = null;
    var view = {
        init: function () {
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function () {
                Lib.doSearchForm($("#searchForm"), highlevelTalentsTable)
            }
        },
        initTable: function () {
            highlevelTalentsTable = table.render({
                elem: '#highlevelTalentsTable',
                height: Lib.getTableHeight(1),
                cellMinWidth: 100,
                method: 'post',
                url: Common.ctxPath + '/cms/highlevelTalents/list.json' // 数据接口
                , page: Lib.tablePage // 开启分页
                , limit: 10,
                cols: [[ // 表头
                    {
                        type: 'checkbox',
                        fixed: 'left',
                    },
                    {
                        field: 'name',
                        title: '姓名',
                        align: 'center',
                        width:"165"
                    },
                    {
                        field: 'declarationObjectText',
                        title: '申报对象类别',
                        align: 'center',
                        width:"400"
                    },
                    {
                        field: 'subsidyCategoryText',
                        title: '申报补贴类别',
                        align: 'center',
                        width:"180"
                    },
                    {
                        field: 'subsidyAmount',
                        title: '补贴金额',
                        align: 'right',
                        width:"135",templet:function (d) {
                        return Common.getMoney(d.subsidyAmount);
                    }
                    },
                    {
                        field: 'businessState',
                        title: '业务状态',
                        align: 'center',
                        width:"135"
                    },
                    {

                        field : 'creationDate',
                        title : '创建日期',
                        align: 'center',
                        width:"180"
                    }

                ]]

            });

            table.on('checkbox(highlevelTalentsTable)', function (obj) {
                var highlevelTalents = obj.data;
                if (obj.checked) {
                    //按钮逻辑Lib.buttonEnable()
                } else {

                }
            })
        },

        initSearchForm: function () {
            Lib.initSearchForm($("#searchForm"), highlevelTalentsTable, form);
        },
        initToolBar: function () {
            toolbar = {
                add: function () { // 获取选中数据
                    Common.post("/cms/common/notLeave.json?declarationType=highlevel_talents", {}, function(data) {
                        var url = "/cms/highlevelTalents/add.do";
                        Common.openDlg(url, "高层次人才>新增");
                    })
                },
                edit: function () { // 获取选中数目
                    var data = Common.getObtainState(table, "highlevelTalentsTable");
                    if (data == null) {
                        return;
                    }
                    var url = "/cms/highlevelTalents/edit.do?id=" + data.id;
                    Common.openDlg(url, "高层次人才>编辑");
                },
                find : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"highlevelTalentsTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/highlevelTalents/findenterprise.do?id="+data.id;
                    Common.openDlg(url,"高层次人才>查看");
                },
                process : function() { // 获取选中数目
                    var businessType = Common.businessType.highlevelTalents;
                    var data = Common.getOneFromTable(table,"highlevelTalentsTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/businessProcess/index.do?businessType="+businessType+"&businessId="+data.id;
                    Common.openDlg(url,"流程信息>编辑");
                },
                del: function () {
                    layui.use(['del'], function () {
                        var delView = layui.del
                        delView.delBatch();
                    });
                }
            };
            $('.ext-toolbar').on('click', function () {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('index', view);

});